#include "widget.h"
#include "ui_widget.h"
#include <QDebug>

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
    // 初始化 输入框
    ui->lineEdit->setPlaceholderText("请输入密码：");
    ui->lineEdit_2->setPlaceholderText("请再次输入密码：");
    ui->lineEdit->setEchoMode(QLineEdit::Password);
    ui->lineEdit_2->setEchoMode(QLineEdit::Password);
    ui->label->setText("输入的密码不能为空！");
    // 初始化 label
    ui->label->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
}

Widget::~Widget()
{
    delete ui;
}

void Widget::compare(const QString &text)
{
    (void)text;
    QString s1 = ui->lineEdit->text();
    QString s2 = ui->lineEdit_2->text();
    if(s1.isEmpty() && s2.isEmpty())
    {
        ui->label->setText("输入的密码不能为空！");
        ui->pushButton->setEnabled(false);
    }
    else if(s1 == s2)
    {
        ui->label->setText("");
        ui->pushButton->setEnabled(true);
    }
    else
    {
        ui->label->setText("两次输入的密码不一致！");
        ui->pushButton->setEnabled(false);
    }
}


void Widget::on_lineEdit_2_textEdited(const QString &text)
{
    compare(text);
}

void Widget::on_lineEdit_textEdited(const QString &text)
{
    compare(text);
}

void Widget::on_pushButton_clicked()
{
    qDebug() << "密码为：" << ui->lineEdit_2->text();
}
